package top.chengdongqing.mishop.order.vo

import top.chengdongqing.mishop.entities.OrderItem
import java.io.Serializable
import java.math.BigDecimal

data class OrderItemVO(
    val id: Int,
    val productId: Int,
    val skuId: Int,
    val productName: String,
    val skuName: String,
    val pictureUrl: String,
    val unitPrice: BigDecimal,
    val quantity: Int,
    val subtotal: BigDecimal
) : Serializable {
    companion object {
        fun of(orderItem: OrderItem): OrderItemVO {
            return OrderItemVO(
                id = orderItem.id,
                productId = orderItem.productId,
                skuId = orderItem.skuId,
                productName = orderItem.productName,
                skuName = orderItem.skuName,
                pictureUrl = orderItem.pictureUrl,
                unitPrice = orderItem.unitPrice,
                quantity = orderItem.quantity,
                subtotal = orderItem.subtotal
            )
        }

        fun of(orderItems: List<OrderItem>): List<OrderItemVO> {
            return orderItems.map { of(it) }
        }
    }
}
